package start;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.HeadlessException;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.URL;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.UIManager;
import com.ter.Form;

import ter.find.pattern.ModelCharge;
import ter.find.pattern.gui.ChangeForm;
import ter.find.pattern.gui.ControlPanel;
import ter.find.pattern.gui.LireFichierXLS;
import ter.find.pattern.gui.WorkPanel;



public class Gui extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	/**/
	JFrame framep=new JFrame("FIND FREQUENT PATTERN");
	JMenuBar  menubar = new JMenuBar();
	JDialog dig=new JDialog();

	/*Panel*/
	JPanel panMotif=new JPanel();
	JPanel panSequence=new JPanel();
	JPanel panControl=new JPanel();
	JPanel panToolsBar=new JPanel();
	WorkPanel panWork;
	

	/*Boutons*/
	JButton bCharger=new JButton("Charger");
	JButton bFichier=new JButton("Charger");
	JButton bAgreger=new JButton("Agreger");
	JButton bChanger=new JButton("Changer");
	public JButton bFind=new JButton("Rechercher");

	/*Menu*/	
	JMenu fichier = new JMenu("Fichier") ;
		JMenuItem quit=new JMenuItem("Quitter");
		JMenuItem help=new JMenuItem("aide");
	JMenu propos=new JMenu("?");
		JMenuItem apropos=new JMenuItem("A propos...");
		JMenuItem aide=new JMenuItem("Help");
	
		
	/*Tabbed Pane*/
		JTabbedPane tabbedPaneCharge=new JTabbedPane();;
		JTabbedPane tabbedPaneAgreger=new JTabbedPane();;
		JTabbedPane tabbedPaneChanger=new JTabbedPane();;
		JTabbedPane tabbedPaneFind=new JTabbedPane();;

	
	public Gui(JMenuBar menubar, JButton bCharger,JButton bFichier, JButton bAgreger,
			JButton bChanger, JButton bFind, JMenu fichier, JMenuItem quit,
			JMenuItem save, JMenu propos, JMenuItem apropos, JMenuItem aide)
			throws HeadlessException {
		super();
		this.menubar = menubar;
		this.bCharger = bCharger;
		this.bAgreger = bAgreger;
		this.bChanger = bChanger;
		this.bFind = bFind;
		this.bFichier = bFichier;
		this.fichier = fichier;
		this.quit = quit;
		this.help = save;
		this.propos = propos;
		this.apropos = apropos;
		this.aide = aide;
	}





	public Gui(ControlPanel c,ChangeForm cp,Form f,LireFichierXLS l) throws HeadlessException {
		panWork=new WorkPanel(c,cp,f,l);
		this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		//pour le cadre
        Container content=this.getContentPane();
		content.setLayout(new BorderLayout());
		
		//position of frame
		Toolkit toolkit = Toolkit.getDefaultToolkit();
		Dimension tailleEcran = toolkit.getScreenSize();
		Dimension tailleFrame = getSize();
		setLocation((tailleEcran.width - tailleFrame.width),(tailleEcran.height - tailleFrame.height));
		
		this.setBounds(30,30,980,600);
		this.setTitle("FIND Pattern");
		this.setLayout(new BorderLayout());
		//this.setVisible(true);
		this.setIconImage(icon(this,"icon/angrenage.png"));
		
		/*Menu*/
		fichier.add(quit);
		fichier.add(help);
		
		/*Menu bar*/
		menubar.add(fichier);
		this.setJMenuBar(menubar);
		
		/*Tools bar Panel*/
		panToolsBar.setBounds(0,0,2000, 30);
		panToolsBar.add(bCharger);
		panToolsBar.add(bAgreger);
		panToolsBar.add(bChanger);
		panToolsBar.add(bFind);
		panToolsBar.add(bFichier);
		
		
		
		/*Add to Content compenent*/
		content.setBackground(Color.decode("#3c5564"));
		content.add(panWork,BorderLayout.CENTER);
		
		help.addActionListener(new HelpActionListener());
		quit.addActionListener(new HelpActionListener());
		setLocationRelativeTo(null);  
	}
	
	
	public class HelpActionListener implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
			// TODO Auto-generated method stub
			Object selec = e.getSource();
			if(selec.equals(help)){
				new Help();
			}
			if(selec.equals(quit)){
				if (JOptionPane.showConfirmDialog(null, "Voulez vous vraiment quitter?\nPenser à sauvegarder votre travail!", "Quitter", JOptionPane.YES_NO_OPTION)==JOptionPane.YES_OPTION){
					setVisible(false);
					System.exit(0);
					setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);	
				}
			}
		}
		
	}

	/*Icons*/
	public static Image icon(JFrame j,String s){
		Toolkit toolkit = Toolkit.getDefaultToolkit();
		URL url = j.getClass().getResource(s);
		Image image = toolkit.getImage(url);
		return image;
	}
	
	/*Boutton form*/
	public static void preference(JButton bouton){
		bouton.setFocusPainted(false);
		bouton.setBackground(Color.decode("#444466"));
		bouton.setContentAreaFilled(false);
		bouton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
		bouton.setForeground(Color.decode("#FFFFFF"));
	}
	
	public void addListener(ActionListener action) {
        bFind.addActionListener(action);
        
    }
	
	public void addChargeListener(ActionListener action) {
        bCharger.addActionListener(action);
    }
	
	/*Look ant feel*/
	static
	 {
		 try
	     {
	      	UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
	     }
		 catch (Exception exception)
	      {
	      	exception.printStackTrace();
	      }
	 }
	
	public static void main(String [] args)
	{
		
		new Splash();
		new ModelCharge();
		Form f=new Form();
		LireFichierXLS l=new LireFichierXLS();
		ChangeForm cp=new ChangeForm();
		ControlPanel c=new ControlPanel();
		Gui g=new Gui(c,cp,f,l);
		g.setBackground(Color.black);
		g.setSize(1100, 700);
		g.setVisible(true);		
	}

}
